import pandas as pd
from pymongo import MongoClient

# 源client
client = MongoClient('mongodb://admin:yzy%40123456@10.11.2.56:27017/')
# 目标数据库
db = client["algorithm"]
# 目标document
collection = db["western_middle_record"]

# 定义固定表头
headers_old = ['checkId', "左脑供氧", "右脑供氧", "脑供血", "眼部", "鼻部", "口周", "左肺功能", "右肺功能",
               "左肺支气管",
               "右肺支气管", "心肌供氧", "心肌供血", "肝", "胆囊,胆管", "胃", "结肠", "前列腺", "植物神经(脊柱)",
               "枕下肌群", "颈椎间盘", "左颈肩肌", "右颈肩肌", "左肩关节", "右肩关节", "胸腰筋膜", "腰椎间盘",
               "腰骶筋膜",
               "左膝关节囊", "左膝关节", "右膝关节囊", "右膝关节", "子宫,宫颈", "左乳腺血管", "左乳腺腺体",
               "右乳腺血管",
               "右乳腺腺体"]

# 定义固定表头
headers = ["checkId",
           "左脑最高层平均",
           "左脑供氧",
           "右脑最高层平均",
           "右脑供氧",
           "眼部最高层平均",
           "左脑最高层最低",
           "右脑最高层最低",
           "左肺最低总数",
           "左肺区域总数",
           "左肺功能",
           "右肺最低总数",
           "右肺区域总数",
           "右肺功能",
           "左支气管区域3总数",
           "左支气管",
           "右支气管区域2总数",
           "右支气管",
           "中间层总数",
           "心肌供血",
           "中间层平均",
           "锁窝最高",
           "心肌供氧",
           "胃1最高层最高",
           "肝最高层最高",
           "胃1",
           "胃2最高总数",
           "胃2最低层总数",
           "胃2中间层总数",
           "胃2最高层总数",
           "胃2",
           "右肠最高总数",
           "右肠最低层总数",
           "右肠中间层总数",
           "右肠最高层总数",
           "右肠功能",
           "左肠最高总数",
           "左肠最低层总数",
           "左肠中间层总数",
           "左肠最高层总数",
           "左肠功能",
           "前列腺最高层最低",
           "肺温度最低",
           "前列腺",
           "子宫三等分最高层个数",
           "子宫最低层个数",
           "子宫中间层个数",
           "子宫最高层个数",
           "子宫",
           "锁窝最高温度",
           "眼睛最高层最高",
           "眼",
           "锁窝最高温度",
           "鼻最高层最高",
           "鼻",
           "锁窝最高温度",
           "口最高层最高",
           "口",
           "左乳腺最高层最高值",
           "左锁窝最高层最低值",
           "左乳腺血管增生",
           "右乳腺最高层最高值",
           "右锁窝最高层最低值",
           "右乳腺血管增生",
           "左乳腺腺体区域总数",
           "左乳腺区域小于肺温度个数",
           "肺平均值",
           "左乳腺腺体",
           "右乳腺腺体区域总数",
           "右乳腺区域小于肺温度个数",
           "肺平均值",
           "右乳腺腺体",
           "左膝关节囊最高层最低值",
           "左膝内侧最低层最高值",
           "左膝关节囊",
           "右膝关节囊最高层最低值",
           "右膝内侧最低层最高值",
           "右膝关节囊",
           "左膝关节最低层最高值",
           "左膝内侧最低层最高值",
           "左膝关节",
           "右膝关节最低层最高值",
           "右膝内侧最低层最高值",
           "右膝关节",
           "左肩最高层平均值",
           "左肩关节炎",
           "右肩最高层平均值",
           "右肩关节炎",
           "左颈最高层平均值",
           "左颈肩肌紧张",
           "右颈最高层平均值",
           "右颈肩肌紧张",
           "左侧脖子最高层总数",
           "右侧脖子最高层总数",
           "颈椎间盘",
           "脖子最高层平均",
           "脖子",
           "胸腰最高层平均",
           "胸腰筋膜炎",
           "腰骶最高层平均",
           "腰骶筋膜炎",
           "腰间盘突出"
           ]
# 查询数据
# query = ["3031ae87-f01e-4477-aa77-8cf35a18f26a",
#          "8428f0bd-db30-48e0-acd3-66d5a1836301",
#          "1323dbf5-52f3-4113-9de5-bcffb522594d",
#          "a7ab2fc1-9860-43d7-a655-3cf9f534159e",
#          "729617b4-e836-49b9-b789-fb85c6705d12",
#          "45f90afd-8986-4964-a8a7-f735ab16ebab",
#          "8847df33-1edb-4c35-9446-c3a468c5a353"]
query = ["63e914ea-11b3-4e46-9cf8-fc53a587f142",
         "5028dc32-d4d0-43ec-bd1f-d72e024c17e3",
         "ba408d37-4c3a-49e3-9a3e-2f689fba2002",
         "dd156ebc-98a0-42a6-b951-bd86b0c59554",
         "251b9390-6892-49c7-86c9-00eddb5454ef",
         "51d6f5da-6495-4321-a066-be848b2cec85",
         "0bd9ff68-f317-416d-94d0-63232e19c30e",
         "1d96e1c4-199b-4db4-8af9-8ed87a3d408d",
         "4ca1dc0e-e17a-463e-bcf7-256fc6663e8d",
         "80436f63-9fe9-4fc0-98c8-a4f40db71d94",
         "7b44e8bd-7199-49e7-bdf7-4797f35d3a76",
         "2078a5d9-8da4-4dd4-88a5-8b743756fdc2",
         "482801d9-cceb-4ed3-81c6-b6c48abf0999",
         "50cfce5d-fb60-45f8-a1e0-c4de7437bab1",
         "86bc39d9-1fbc-4154-872e-39efbedb987b",
         "e16975b2-941b-42e0-aeb6-24e9d452e072",
         "c57d8ece-8259-4374-8cfa-1395d7f41a44",
         "c75d7f6e-b5df-404e-a58b-e4b4ff35e398",
         "62d249c1-c104-48d2-a69c-369042ae0361",
         "e31e5665-e479-4fcc-abe4-acd251dbd2ea",
         "eb60a45b-d914-4b81-9881-60467bf2283a",
         "b3d9c997-a442-4ea2-998b-3615808e03b2",
         "2356b6d1-d93f-4af9-a098-41b9e8e02944",
         "7ddc9dbe-f79f-45c5-9fa5-8a7e1edfb2f9",
         "e2448225-18d8-4d05-b780-e0c8f4f362d8",
         "71145108-cd5b-404d-bfb2-230b504aae4a",
         "0ab59033-891d-4e62-8798-11464993b768",
         "8fe2a1a9-f7c8-4aee-b3a7-254522179f52",
         "ef9dfff8-d5b5-4160-b71e-3da2ba13e2e0",
         "30098080-3c94-42d4-978e-c8ed236d16f0",
         "cdd79a47-0550-40a5-8a36-e5f2c0a32c26",
         "4fa2bb16-e540-41e9-8557-065a3b9a09e7",
         "90f9a59b-3853-4341-a80a-eebd3c5f28fd",
         "d09e085f-2c4d-477e-8885-9c6944cf69f1",
         "0e28a31c-0a63-4045-aa64-0e3d6745e854",
         "b2da1650-02d3-483f-9f5b-270723a0baac",
         "02adedd2-edf3-4a55-a542-90eea68c8493",
         "513dfa89-5cb4-4a7d-97fc-8748f14a1f8e",
         "485dde02-150a-4605-90da-4890f468b5cc",
         "71f5a933-54d1-40cc-b043-799b42af88a7",
         "4ae50285-1646-4849-af34-6a8059805086",
         "2db7d221-dfa4-4320-8084-b95c83ef1f66",
         "1ce32490-df68-4d9a-ad63-50fcc8c40505",
         "18f0d371-69ed-4855-93a5-1546253c752a",
         "7b47b0d8-9315-4a29-96c0-fedf12098a5f",
         "1ede5f44-d6eb-4239-9e36-37c890c7149b",
         "b16089ee-dbae-4ba1-abe1-6861fdf933d7",
         "3086e9c4-3687-49ff-b601-9879df63685c",
         "7f35a07d-0992-4759-91fe-5c4f8147c177",
         "7615da68-db48-4d6b-9053-f0e6d88c2331",
         "09f5c272-b6a9-4b88-902e-89edba94831f",
         "0b5fa50c-35c4-4112-b3cf-ae96eb12bf24",
         "7c99d929-9e13-4dcb-806f-e6107af9f337",
         "01855855-ab44-4c8e-a7ce-1fb652527968",
         "f4e6be19-ff38-4c78-8de5-b343a3f87f33",
         "afc54720-8c55-4e0f-8517-61ac1eb645db",
         "7493cfec-5ca8-480a-9c9a-37b31d8b82fe",
         "20a53c48-252e-4c9c-a049-8fc4b99c9b7a",
         "a562a737-d2f0-4aa5-be6a-ca45d72a746d",
         "5bf4c5a6-c2f4-4162-9101-180807d2069b",
         "941b3eab-12c8-45c4-8a98-289a845e0d65",
         "fd2e579e-2427-427b-b74b-7d06ad255fde",
         "770b8367-a1ac-4f18-992b-d23b46e89528",
         "689e8280-924c-418d-9d03-5aa042cc2de8",
         "d3393f83-20b7-4315-8495-ca920e347d72",
         "5b1c70dd-f48d-40a1-9a9e-3a5af5b07502",
         "1b801278-a99a-447e-b97a-854d3e61e07b",
         "014e27e0-7e0e-4de6-9d7e-4b1008c2ab39",
         "d0e64187-2419-44d3-82ff-4bfa9d0ad5f1",
         "96ad394a-a51d-4017-9518-115b0bb0eeb4",
         "9dc20886-383c-4efd-b7a1-9146ac92f64b",
         "46e10fe2-261e-45fc-87e9-357f7d8b7064",
         "7d106717-8996-4bee-9be8-c9d3d2040bf1",
         "207c3254-47f3-40a9-88b6-30acdff9e60d",
         "465e6ea8-5ba0-472a-8498-1c21c8900c74",
         "15fe9587-7634-477a-914f-ea9fcab2dfb6",
         "3233d0b8-52eb-4955-be45-2239da771e82",
         "d5b4fecc-9557-4385-ae08-01d7b72294f4",
         "6eb3524a-986d-42c6-838e-21d9913b52dd",
         "7016ba0f-d419-4f36-90ef-6e8610895766",
         "47e55a7c-f5e9-425c-b8d3-1454b7268ec2",
         "815368e4-9148-402c-9614-4d598a3befa2",
         "e5236fcd-a9d7-48a4-8605-8e238e0ee201",
         "15ed2e69-7d3f-4bfd-8418-b3535b5b10ee",
         "7c40d5a5-4356-47e0-bdba-9181d8bc4633",
         "f2282e80-eb85-4854-8dfb-06b88947b9ed",
         "078859d1-df6b-4e65-a896-51bdc537139b",
         "a6df43a9-e47f-4961-acf3-4e44543e3375",
         "be810274-93fd-408d-a756-3929b85653f6",
         "c3146cc5-1f53-4d3e-8ad7-af3456ed2bdf",
         "7c86a83a-d790-44f4-b295-bdf18db6f5e3",
         "cc0c5ece-5d86-48d4-9c34-16a98de2a5a8",
         "b5d4bee6-a745-4bfa-83d2-b619583edda7",
         "c1408f58-696b-44f6-84ce-46b049894f71",
         "7d6418f7-f6ae-45a2-89d2-d33cb45352fb",
         "12cd18ea-9988-4411-8385-ac51accb99e0",
         "9e94152c-a984-4053-b610-e4cac6917eb3",
         "3dceccb5-1190-4357-96a7-ce764b1e50ac",
         "519878a8-96f6-491e-a35c-a9c9c711ea0d",
         "f7614962-10f2-46c1-9ddc-d4fe2c5c3c8e",
         "2392cc14-d420-4b0c-848d-e29e339c33a3",
         "f7d21563-3bff-4346-9600-034b8f6409a9",
         "257f6755-d58d-46c9-a7e2-256d50e19950",
         "6b1514bf-6ac9-4535-85af-f6c148281a09",
         "7cf86b77-1714-430e-955a-a58e35f87a2d",
         "f9937339-e8f6-4f22-b4b6-95e0dd9e87d1",
         "8938795d-fafd-4ac2-86f0-0c5e16ad5bca",
         "30711e0c-22fa-4d8c-bd17-08be107271b8",
         "fada5b98-86fa-4a73-82da-cd71d7eca0f6",
         "0568c69d-7ecb-4a03-a5dd-15d37e6f46d1",
         "641acf73-361c-4549-adad-3372c3678a51",
         "36ec7a3b-a02e-45d9-b607-40ba2c972c8f",
         "6c076c7b-e7d4-49c4-a03e-7e2f0d272f51",
         "1cda83bf-4dbc-4238-83c0-a7916d6f4cf1",
         "b16b046a-60a8-440f-9e81-23d0d65a4b20",
         "dba95168-597e-4a7f-af65-7f867fba2fd2",
         "f48ccb0b-04a5-4f6b-a2a5-1437a061222e",
         "ddba2b9f-e3fe-4329-8ea4-29bce55e9e0e",
         "5e24ba43-26b3-491b-b094-f87a9887b155",
         "023832e9-804f-4913-8a4f-751e35c34d1e",
         "636a7d0c-3de3-4112-a79b-695dd3c892ef",
         "0777838f-74dd-4ffe-8c84-c2e20cc397d5",
         "05f7b568-5ec2-4d1c-9cef-9f6b91b7f3c5",
         "a64785a4-757d-42c5-84cd-4cf9141f96d9",
         "14431def-eb43-46ff-8a0c-2a76a4f0ca3f",
         "d9660489-8c99-4f50-8b2e-bdb2d96ccdac",
         "e9515582-e9ce-4ebd-8c8a-8bc49704c384",
         "8bb2f785-0b60-42ba-a82e-ef842be0e93f",
         "0034abd5-9dc3-465f-b7e0-771d3de44d14",
         "49854a9c-ab3d-4bfe-8cd7-8fab5c62df67",
         "5914e051-d4fb-406c-b75b-97a42f8bdb50",
         "d3efe0c1-435a-4204-bf0b-13389647a571",
         "2eb862f9-1f55-4c8f-a40a-bf05190cf937",
         "ee0a988f-2dfc-40d5-9b6a-b586f5a3e3ed",
         "7f78fc38-7353-4533-8373-7aaebaaa8aee",
         "28713e6e-754a-49cb-8fdb-db4af7c0b76f",
         "c8c1fad3-ef4f-40a7-afed-5dbfa893a7af",
         "075f0c8a-4875-465a-a12f-713131c82f00",
         "c47e2d97-e2a2-4021-a9e7-f2949c71a9db",
         "9c4eff7e-1954-4dc9-9ada-521d1d41bb9f",
         "8674a9c6-f6f5-418f-a187-2826dfa74291",
         "b5fc1073-0272-41ee-89e4-5a357079b668",
         "795650f0-a6a9-4406-b98a-746e9bc6cde6",
         "c128fac2-9652-4ea1-a289-4a39ff2bd0fd",
         "d242901b-282b-40ce-bb0b-72c3d927241f",
         "6ba6a51c-b3a8-4e46-9b70-47b02a7e0314",
         "843311c5-cf87-433b-a647-632542c1c223",
         "8c4f976c-8db4-4c3c-90f7-3709e3fde197",
         "212a8c7b-2aa5-4679-8767-7a747587af41",
         "227d9a9e-bdd9-46ac-b8ad-375349bd39fc",
         "c748e1d6-07f1-463e-ba6b-25b12b7f3bba",
         "80803aba-02ff-4f09-ae3c-be194385d891",
         "d531ba2f-740e-43d2-9639-5bbefd554c78",
         "e8980e6d-7898-4ec5-a25a-428a3dd71312",
         "24011337-0cb4-49b7-ba73-e373010bb0a5",
         "97363c8e-6173-4f55-83c7-168ecbbd94c9",
         "d062d00f-5b28-46ab-85e1-87137fb77d36",
         "3d008a38-4995-4948-bd08-921bf3b9233d",
         "f2ca9b3c-cd96-41c6-ba77-155e60486e24",
         "408deaed-48dc-4a78-8909-884f8cc74455",
         "e517908d-18cf-444c-af0b-fa89303854e9",
         "51c1fec9-5c95-4729-a566-c84dafb52927",
         "512e75ef-a168-4dad-b7e7-088929e002a5",
         "ef39cb58-9067-45c9-b2c2-6800dd195d82",
         "1aae6e76-3b61-46af-809f-66a25ef80d4f",
         "86c602bc-27da-4b78-aabb-47c9cb7aa035",
         "e9427a7f-a686-4148-8f88-b7403499dd3c",
         "bb75205b-433e-4a8a-bb34-5cc1ec3692bb",
         "2abce754-6618-48ce-b3c2-b33bb8949b7c",
         "35e64d47-9dba-43d3-a70c-0eec0ec2cd49",
         "e11ae9c8-602c-4dd5-a872-c1f448844a19",
         "94570fd8-edb7-4e86-992d-6ca089085266",
         "e1b91003-ad44-4120-ad4c-6dfdf5abdf94",
         "a0f2f04e-eb52-4878-b369-cc4a55f5a174",
         "449ec034-1c64-42f1-b483-964d9501d20b",
         "8511c731-6c25-4564-8074-ad0612316a35",
         "9642e067-1512-42f3-a5f8-71a45838b681",
         "7cf6f6c8-cfcb-4b73-bd4e-c63379ba3844",
         "2d056041-a190-4ede-9b20-f053e7bf62d1",
         "37a784db-15ff-48d3-9663-7e6a0421d441",
         "df27167a-73b8-4c59-9f25-d2b2ec8cf80b",
         "16785b5e-f42d-4ced-aaa4-2c2ad74136a3",
         "4b54de87-76b7-4cde-a90f-6db8b578df86",
         "8e0505d0-275f-444b-aec7-bc83b093ff8b",
         "17ed836e-3861-499d-a58d-f439527c8e0c",
         "4c71b4fa-8bf5-4c64-ad70-bd46b77fa3a7",
         "1051a615-5e9e-4701-8708-5214cb361e38",
         "9ba07da2-bc40-4d71-8f28-13502b1bccc1",
         "89e77aa0-ea92-43a5-9ab1-953ada5d3c7e",
         "952ebdc1-d08e-4845-9bb8-6c8481b60dbe",
         "8f1c348a-dfa1-4ad3-bde2-8b4228b2f872",
         "5dde2305-9894-404d-a921-d6e7e45dd6cd",
         "eb522c71-be2b-420a-923c-835c6abf6abd",
         "18d3f4ca-645d-4374-b010-b05d7f6a5b27",
         "6c7679ee-defa-4db0-bc04-85d3299d2947"]

# 根据checkId in查询
# data = collection.find({"requestId": "e5c09ce8-a7c6-46d4-ba5c-7bfdd7f6bc17"})
data = collection.find({"checkId": {"$in": query}})

result_out = []
for item in data:
    # result_out_list = {'checkId': item['checkId']}
    # explain_list = item['explain']
    # for exp in explain_list:
    #     result_out_list[exp['name']] = (exp['score'])
    print(item['checkId'], item['resultMiddleMap'])
    result_out_list = item['resultMiddleMap']
    result_out_list['checkId'] = item['checkId']
    row = [result_out_list.get(header, '') for header in headers]
    result_out.append(row)

df = pd.DataFrame(result_out, columns=headers)

# 保存为Excel文件
df.to_excel('output_new_03.xlsx', index=False)
